using Microsoft.AspNetCore.Mvc;
using ZR.Model.FacManage.Dto;
using ZR.Model.FacManage;
using ZR.Service.FacManage.IFacManageService;
using ZR.Admin.WebApi.Filters;
using ZR.Service.FacManage;

//创建时间：2025-03-30
namespace ZR.Admin.WebApi.Controllers.FacManage
{
    /// <summary>
    /// 工位信息
    /// </summary>
    [Verify]
    [Route("FacManage/FacStation")]
    public class FacStationController : BaseController
    {
        /// <summary>
        /// 工位信息接口
        /// </summary>
        private readonly IFacStationService _FacStationService;

        public FacStationController(IFacStationService FacStationService)
        {
            _FacStationService = FacStationService;
        }

        /// <summary>
        /// 查询工位信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("pageList")]
        [ActionPermissionFilter(Permission = "fac:station:list")]
        public IActionResult PageFacStation([FromQuery] FacStationQueryDto parm)
        {
            var response = _FacStationService.GetPageList(parm);
            return SUCCESS(response);
        }
        /// <summary>
        /// 获取工位树信息
        /// </summary>
        /// <param name="disabledFactory">禁用工厂选择</param>
        /// <param name="disabledWorkshop">禁用车间选择</param>
        /// <param name="disabledLine">禁用产线选择</param>
        /// <returns></returns>
        [HttpGet("treeList")]
        [ActionPermissionFilter(Permission = "fac:station:list")]
        public IActionResult TreeFacStation(bool disabledFactory, bool disabledWorkshop, bool disabledLine)
        {
            var response = _FacStationService.GetTreeList(disabledFactory, disabledWorkshop, disabledLine);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询工位信息详情
        /// </summary>
        /// <param name="StationId"></param>
        /// <returns></returns>
        [HttpGet("{StationId}")]
        [ActionPermissionFilter(Permission = "fac:station:query")]
        public IActionResult GetFacStation(string StationId)
        {
            var response = _FacStationService.GetInfo(StationId);

            var info = response.Adapt<FacStationDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加工位信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "fac:station:add")]
        [Log(Title = "工位信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFacStation([FromBody] FacStationDto parm)
        {
            var modal = parm.Adapt<FacStation>().ToCreate(HttpContext);

            var response = _FacStationService.AddFacStation(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新工位信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "fac:station:edit")]
        [Log(Title = "工位信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFacStation([FromBody] FacStationDto parm)
        {
            var modal = parm.Adapt<FacStation>().ToUpdate(HttpContext);
            var response = _FacStationService.UpdateFacStation(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除工位信息
        /// </summary>
        /// <returns></returns>
        [HttpPost("delete")]
        [ActionPermissionFilter(Permission = "fac:station:delete")]
        [Log(Title = "工位信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFacStation([FromBody] string[] ids)
        {
            var response = _FacStationService.DeleteFacStation(ids);
            return ToResponse(response);
        }

    }
}